<?php
/*
 * 评论类
 */
class pinglunAction extends Action {
	
	/**
	 * 显示html页面
	 */
	function add(){

		$this->display();
		
	}
	
	/**
	 * 获取客栈评论的列表
	 */
	function getpinglunlist($hid){
		
		if(!is_numeric($hid)) return "";
		$mr=M("pinglun");
		$sql="select * from ".DQ."pinglun where pinglun2=".$hid." and pinglun3=604 order by pinglun0 desc limit 0,10";
		$rs=$mr->query($sql);
		$this->assign("rs",$rs);
		return $this->fetch("pinglun:getpinglunlist");
		
	}
	
	/**
	 * 获取一个客栈总的评分数
	 * @param $hid
	 */
	function getonehotelpingf($hid){
		if(!is_numeric($hid)) return "";
		$mr=M("pinglun");
		$sql="select count(*) as tnum, sum(pinglun9+pinglun10+pinglun11+pinglun12+pinglun13+pinglun14)as onenum
		from ".DQ."pinglun where pinglun2=".$hid;
		$rs=$mr->cache(true)->query($sql);
		if($rs[0]){
			
			$t= ($rs[0]["onenum"]*20)/($rs[0]["tnum"]*6);
			$t=number_format($t,2);
			return(getsubstr($t,"/^0/")=="0")?100:$t;
			
		}else{
			return "";
		}
		
	}
	
	/**
	 * 获取一个客栈的每一项的百分比，比如位置的总得分数
	 * @param $hid 客栈id
	 * @return 返回一个数组，k为字母s+字段名,v为其值,统计个数为tnum
	 */
	function getpinglunhotelev($hid){
		if(!is_numeric($hid)) return "";
		$mr=M("pinglun");
		$sql="select count(*) as tnum,sum(pinglun9) as spinglun9,sum(pinglun10) as spinglun10,sum(pinglun11) as spinglun11,
		sum(pinglun12) as spinglun12,sum(pinglun13) as spinglun13,sum(pinglun14) as spinglun14 from ".DQ."pinglun
		where pinglun2=$hid
		";	
		$rs=$mr->query($sql);
		$ra=$rs[0];
		if($rs[0]){
			$ra["spinglun9"]=number_format($ra["spinglun9"]*20/$ra["tnum"],2);
			$ra["spinglun10"]=number_format($ra["spinglun10"]*20/$ra["tnum"],2);
			$ra["spinglun11"]=number_format($ra["spinglun11"]*20/$ra["tnum"],2);
			$ra["spinglun12"]=number_format($ra["spinglun12"]*20/$ra["tnum"],2);
			$ra["spinglun13"]=number_format($ra["spinglun13"]*20/$ra["tnum"],2);
			$ra["spinglun14"]=number_format($ra["spinglun14"]*20/$ra["tnum"],2);
		}
		return $ra;
		
	}
	
	
	
	
	
}

?>